//go:build windows

package download

import (
	"golang.org/x/sys/windows"
	"os"
)

// 为文件加锁
func lockFile(file *os.File) error {
	handle := windows.Handle(file.Fd())
	var overlapped windows.Overlapped

	return windows.LockFileEx(handle, windows.LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &overlapped)
}

// 解锁文件
func unlockFile(file *os.File) error {
	handle := windows.Handle(file.Fd())
	var overlapped windows.Overlapped

	return windows.UnlockFileEx(handle, 0, 1, 0, &overlapped)
}
